//
//  main.cpp
//  二叉树Xcode
//
//  Created by asus on 2020/7/17.
//  Copyright © 2020 唐沈飞. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

typedef char elemdata;

typedef struct BitNode
{
    elemdata data;
    struct BitNode *lchild;
    struct BitNode *rchild;
}BitNode, *BiTree;

/*ABD   CE   */

//«∞–Ú¥¥Ω®∂˛≤Ê ˜
void CreateBiTree(BiTree &T)
{
    elemdata c;
    scanf("%c", &c);
    if( ' ' == c)
    {
        T = NULL;
    }
    else
    {
        T = (BiTree)malloc(sizeof(BitNode));
        T->data = c;
        CreateBiTree(T->lchild);
        CreateBiTree(T->rchild);
    }
}

void visit(elemdata c, int level)
{
    cout << c << "µƒ≤„ ˝Œ™£∫" << level << endl;
}

//«∞–Ú±È¿˙
void PreOrderTraverse(BiTree T, int level)
{
    if(T != NULL)
    {
        visit(T->data,level);
        PreOrderTraverse(T->lchild, level + 1);
        PreOrderTraverse(T->rchild, level + 1);
    }
}
//÷––Ú±È¿˙
void InOrderTraverse(BiTree T, int level)
{
    if(T != NULL)
    {
        InOrderTraverse(T->lchild, level + 1);
        visit(T->data,level);
        InOrderTraverse(T->rchild, level + 1);
    }
}

//∫Û–Ú±È¿˙
void PosOrderTraverse(BiTree T, int level)
{
    if(T != NULL)
    {
        PosOrderTraverse(T->lchild, level + 1);
        PosOrderTraverse(T->rchild, level + 1);
        visit(T->data,level);
    }
}

int main(void)
{
    int level = 0;
    BiTree T = NULL;
    CreateBiTree(T);
    cout << "«∞–Ú±È¿˙µƒΩ·π˚Œ™£∫" << endl;
    PreOrderTraverse(T, level);
    cout << "÷––Ú±È¿˙µƒΩ·π˚Œ™£∫" << endl;
    PreOrderTraverse(T, level);
    cout << "∫Û–Ú±È¿˙µƒΩ·π˚Œ™£∫" << endl;
    PreOrderTraverse(T, level);
    cout << "hello world" << endl;
    return 0;
}

